package com.example.jqying.androiddemo.recyclerView.activity;

import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.Toast;

import com.example.jqying.androiddemo.R;
import com.example.jqying.androiddemo.recyclerView.adapter.LinearAdapter;

public class LinearRecyclerViewActivity extends AppCompatActivity {

    private final  String TAG = "LinearRecyclerView";

    private RecyclerView mRvMain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG,"onCreate");


        setContentView(R.layout.activity_linear_recycler_view);

        /*
        *   recycleView 使用流程
        *   1。findView
        *   2。设置布局控制器（对应其Item使用的layout ？）
        *   3。设置适配器，需要自己定义适配器本例子使用自定义的LinearAdapter
        *   4。适配器会设置Item的数量和样式
        *   5。转到LinearAdapter--->>
         */
        mRvMain = (RecyclerView) findViewById(R.id.rv_main);
        mRvMain.setLayoutManager(new LinearLayoutManager(LinearRecyclerViewActivity.this));

        //添加分割线OK 渐变色
        //这里运用了系统自带的分割线装饰，可以简单的只传入分割线方向
        //或者自定义分割线样式，通过自定义Drawable
        //
        DividerItemDecoration divider = new DividerItemDecoration(this,DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(this,R.drawable.custom_linear_divider));
        mRvMain.addItemDecoration(divider);

//        mRvMain.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL)); //添加分割线 OK

//        mRvMain.addItemDecoration(new MyDecoration());//添加分割线（未成功）
        mRvMain.setAdapter(new LinearAdapter(LinearRecyclerViewActivity.this, new LinearAdapter.OnitemClickListener() {
            @Override
            public void onClick(int pos) {
                Toast.makeText(LinearRecyclerViewActivity.this,"Clicked : "+ pos,Toast.LENGTH_SHORT).show();
            }
        }));




    }
//    class MyDecoration extends RecyclerView.ItemDecoration{
//
//        @Override
//        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
//            super.getItemOffsets(outRect, view, parent, state);
//            outRect.set(0,0,getResources().getDimensionPixelOffset(R.dimen.dividerHeight),0);
//
//
//        }
//
//        @Override
//        public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
//            super.onDraw(c, parent, state);
//        }
//
//
//    }
}
